package com.mr.security.web.commons.validate.controller;

import com.mr.security.web.commons.utils.Constants;
import com.mr.security.web.commons.validate.ValidateCodeProcessorHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Class: ValidateCodeController
 * User (作者):MRui
 * TODO (描述)：图形验证码，短信等校验
 * Date 2019-01-20 23:42
 */
@RestController
public class ValidateCodeController {

    /** 验证码类型处理人（获取验证码的类型sms/image） */
    @Autowired
    private ValidateCodeProcessorHolder validateCodeProcessorHolder;

    /**
    * User (作者): MRui
    * TODO (描述)：通过url地址后面的sms/image辨别采用那种验证码处理机制
    * Data：2019-01-26 12:22
    */
    @GetMapping(Constants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{type}")
    public void createCode(HttpServletRequest request, HttpServletResponse response, @PathVariable String type)
            throws Exception {
        //通过ValidateCodeProcessorHolder验证码处理器管理员根据type选择验证码处理器进行处理
        validateCodeProcessorHolder.findValidateCodeProcessor(type).create(new ServletWebRequest(request, response));
    }

}
